(defpackage #:markov-algorithm/cli
  (:use #:cl)
  (:export #:main))

(in-package #:markov-algorithm/cli)

(defun main (args)
  "CLI interface to Markov algorithms"
  (loop with file = (first args)
        with scheme = (with-open-file (in file :direction :input)
                        (read in))
        with compiled-scheme = (markov-algorithm:compile-markov-algorithm scheme)
        for line = (read-line nil nil)
        while line
        for transformed-line = (funcall compiled-scheme line) 
        do (if (null transformed-line)
               (error "Iteration limit is reached.")
               (write-line (funcall compiled-scheme line)))
        finally (return t)))
